package cn.tedu.view;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Random;

@WebServlet(name = "demo01")
public class Demo01 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Access-Control-Allow-Origin","*");
        // 每次页面发起请求，向后台返回一组数据，格式为[120, 200, 150, 80, 70, 110, 130]
        String result = "[";
        for (int i = 0; i < 6; i++) {
            int num = new Random().nextInt(100);
            result=result+num+",";
        }
        int num = new Random().nextInt(100);
        result=result+num+"]";
        response.getWriter().write(result);
    }
}
